var Page = function(){
    this.init();
};
Page.prototype = {
    params: {
        passport: '',
        page:1,
        listRows:15,
        total: 0,
    },
    init: function(){
        this.initParams();
        this.initEvent();
    },
    initParams: function(){
        this.params.passport = Pub.getCookie('_PASSPORT');
    },
    getData: function(){
        var _this = this;
        var paramsObj = {
            passport: _this.params.passport,
            page:_this.params.page,
            listRows:_this.params.listRows,
        };
        Api.loginloglist(paramsObj, function(data){

            _this.getDataList(data.list);
            _this.params.total = data.totalPages;
            layui.use('laypage', function(){
                var laypage = layui.laypage;
                //执行一个laypage实例
                laypage.render({
                  elem: 'page',
                  index: 1,
                  theme: '#3498db',
                  curr:  _this.params.page,
                  count: _this.params.total, //数据总数，从服务端得到
                  hash: 'curr_page',
                  layout: [ 'prev', 'page', 'next', 'skip'],
                  jump: function(obj, first){
                    _this.params.page = obj.curr;
                    //obj包含了当前分页的所有参数，比如：curr当前页
                    var Params = {
                        passport: _this.params.passport,
                        page:_this.params.page,
                        listRows:_this.params.listRows
                    };
                    Api.loginloglist(Params, function(data){
                      _this.getDataList(data.list);
                    })
                  }
                });
            });
        });
    },
    getDataList: function (data) {
        var _this = this;

        if (data && data.length > 0) {
            var html = '', i = 0, len = data.length;
            for (i; i < len; i++) {
                html+='<tr>'+
                            '<td class="text-c">'+(i+1)+'</td>'+
                            '<td class="text-c">'+data[i].gmt_create+'</td>'+
                            '<td class="text-c">'+data[i].ip+'</td>'+
                            '<td class="text-c">'+data[i].province+data[i].city+'</td>'+
                            '<td class="text-c">'+data[i].platform+'</td>'+
                        '</tr>';
            }
            $('#List').html(html);
            $('tfoot').css('display', 'table-footer-group');
        }else{
            var html='<tr>'+
                        '<td class="text-c c-666" colspan="10" >暂无数据</td>'+
                    '</tr>';
            $('#List').html(html);
            $('tfoot').css('display', 'none');
        }
    },
    initEvent: function(){
        var _this = this;
        _this.getData();
    }
};
var page = new Page();